package com.example.zaq.rest;

import com.example.zaq.dao.AspLogDao;
import com.example.zaq.model.AspLog;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 20210524  zaq  操作日志
 * @author 阿恩
 * @date 2021/5/2420:53
 */
@RestController
@RequestMapping("/log")
public class AspLogRest {
    @Autowired
    SqlSessionFactory factory;

    /**
     * 查询操作日志
     * http://localhost:9090/log/getAll
     * @param body
     * @return
     */
    @PostMapping("getAll")
    @ResponseBody
    public List<AspLog> getAll(@RequestBody AspLog body){
        List<AspLog> aspLog=null;
        try{
            System.out.println("获得值:"+body);
            SqlSession sess=factory.openSession();
            AspLogDao aspLogDao=sess.getMapper(AspLogDao.class);
            aspLog=aspLogDao.getPage(body);
            sess.close();
            System.out.println(aspLog);
            System.out.println("查询说说分组模板结束");
            return aspLog;
        }catch (Exception e){
            System.out.println(e.getMessage());
        }finally {
            return aspLog;
        }
    }

    /**
     * 查询操作日志数量
     * http://localhost:9090/log/getCount
     * @return
     */
    @PostMapping("getCount")
    @ResponseBody
    public int getCount(@RequestBody AspLog body){
        int aspLog=0;
        try{
            System.out.println("获得值:"+body);
            SqlSession sess=factory.openSession();
            AspLogDao aspLogDao=sess.getMapper(AspLogDao.class);
            aspLog=aspLogDao.getCount(body).getCount();
            sess.close();
            System.out.println(aspLog);
            System.out.println("查询说说分组模板结束");
            return aspLog;
        }catch (Exception e){
            System.out.println(e.getMessage());
        }finally {
            return aspLog;
        }
    }
}
